#include <bits/stdc++.h>

using namespace std;

const int maxn=1000005;
char s1[maxn],s2[maxn];
char sta[maxn];int fi[maxn];
int head;
int fail[maxn];

int main(){
    int l1,l2,fix;

    scanf("%s%s",s1+1,s2+1);
    l1=strlen(s1+1);
    l2=strlen(s2+1);
    fix=0;
    for(int i=2;i<=l2;i++){
        while(fix&&s2[fix+1]!=s2[i]) fix=fail[fix];
        if(s2[fix+1]==s2[i]) fix++;
        fail[i]=fix;
    }
    fix=0;
    for(int i=1;i<=l1;i++){
        fix=head?fi[head-1]:0;
        sta[head]=s1[i];
        while(fix&&s2[fix+1]!=s1[i]) fix=fail[fix];
        if(s2[fix+1]==s1[i]) fix++;
        if(fix==l2) head-=l2;
        else fi[head]=fix;
        head++;
    }

    for(int i=0;i<head;i++) putchar(sta[i]);
    putchar('\n');
    return 0;
}
